//
//  PPAlbumService.m
//  pickpic
//
//  Created by GaoYongyue on 16/9/9.
//  Copyright © 2016年 MicroDream. All rights reserved.
//

#import "PPAlbumService.h"
#import "PPNetworkManager.h"

@implementation PPAlbumService
/**
 *  创建相册
 *
 *  @param albumTitle      相册标题
 *  @param albumDesc       相册说明描述文字
 *  @param privacy         隐私设置，1:所有人可见;2:仅自己可见;4:所有朋友可见;8:选中的朋友可见;16:选中的朋友不可见;
 *  @param privacySettings 当隐私设置为8或者16时，为选中的朋友列表
 *  @param commentSetting  是否可以评论，1可以，2不可以
 *  @param tags            标签id的数组
 *  @param pictures        以本地文件名作为客户端标识
 *  @param callback        回调
 */
+ (void)createAlbumWithTitle:(NSString *)albumTitle
                        desc:(NSString *)albumDesc
                     privacy:(NSInteger)privacy
             privacySettings:(NSArray *)privacySettings
              commentSetting:(NSInteger)commentSetting
                        tags:(NSArray *)tags
                    pictures:(NSArray *)pictures
                    callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:albumTitle forKey:@"title"];
    [params setSafeObject:albumDesc forKey:@"description"];
    [params setSafeObject:@(privacy) forKey:@"privacy"];
    [params setSafeObject:privacySettings forKey:@"privacySetting"];
    [params setSafeObject:@(commentSetting) forKey:@"comment"];
    [params setSafeObject:tags forKey:@"tags"];
    [params setSafeObject:pictures forKey:@"pictures"];

    [[PPNetworkManager sharedInstance] post:@"ablum/create" params:params callback:^(id data, NSError *error) {
        !callback ?: callback(data, error);
    }];
}


/**
 *  获取我的相册信息
 *  当所有参数都为空时，返回该用户所有的全部相册
 *  否则，则按照给定参数进行联合查询，并返回符合条件的相册
 *
 *  @param keyword  搜索关键字，可以为空
 *  @param ablumIDs 相册ID数组，可以为空
 *  @param tagID    标签id
 *  @param isHotTag 标签是否为热门标签
 *  @param callback 回调
 */
+ (void)fetchMyAlbumsWithKeyword:(NSString *)keyword
                        ablumIDs:(NSArray *)ablumIDs
                           tagID:(NSInteger)tagID
                        isHotTag:(BOOL)isHotTag
                        callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:keyword forKey:@"keyword"];
    [params setSafeObject:ablumIDs forKey:@"ablumids"];
    [params setSafeObject:@(tagID) forKey:@"tagid"];
    [params setSafeObject:@(isHotTag) forKey:@"isHotTag"];

    [[PPNetworkManager sharedInstance] post:@"ablum/list" params:params callback:^(id data, NSError *error) {
        !callback ?: callback(data, error);
    }];
}


/**
 *  获取他人相册信息
 *
 *  @param ownerUserID 被查看的userid
 *  @param callback    回调
 */
+ (void)fetchAlbumsWithOwnerUserID:(NSString *)ownerUserID
                          callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:ownerUserID forKey:@"owner"];

    [[PPNetworkManager sharedInstance] post:@"ablum/view" params:params callback:^(id data, NSError *error) {
        !callback ?: callback(data, error);
    }];
}

/**
 *  删除相册
 *
 *  @param albumID  相册ID
 *  @param callback 回调
 */
+ (void)deleteAlbumWithAlbumID:(NSInteger)albumID callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:@(albumID) forKey:@"ablumid"];

    [[PPNetworkManager sharedInstance] post:@"ablum/remove" params:params callback:^(id data, NSError *error) {
        !callback ?: callback(data, error);
    }];
}

/**
 *  更新编辑相册
 *  编辑相册信息接口是为了更新相册自身的信息，而不涉及到相册内图片的信息，关于图片的操作有单独的接口。
 *
 *  @param albumID         相册id
 *  @param albumTitle      相册标题
 *  @param albumDesc       相册说明描述文字
 *  @param privacy         隐私设置，1:所有人可见;2:仅自己可见;4:所有朋友可见;8:选中的朋友可见;16:选中的朋友不可见
 *  @param privacySettings 当隐私设置为8或者16时，为选中的朋友列表，其他则忽略此字段
 *  @param commentSetting  是否可以评论，1可以，2不可以
 *  @param coverImg        七牛的资源key
 *  @param tags            标签id的数组
 *  @param callback        回调
 */
+ (void)updateAlbumWithAlbumID:(NSInteger)albumID
                    albumTitle:(NSString *)albumTitle
                     albumDesc:(NSString *)albumDesc
                       privacy:(NSInteger)privacy
               privacySettings:(NSArray *)privacySettings
                commentSetting:(NSInteger)commentSetting
                      coverImg:(NSString *)coverImg
                          tags:(NSArray *)tags
                      callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:albumTitle forKey:@"title"];
    [params setSafeObject:albumDesc forKey:@"description"];
    [params setSafeObject:@(privacy) forKey:@"privacy"];
    [params setSafeObject:privacySettings forKey:@"privacySetting"];
    [params setSafeObject:@(commentSetting) forKey:@"comment"];
    [params setSafeObject:tags forKey:@"tags"];
    [params setSafeObject:coverImg forKey:@"coverImg"];

    [[PPNetworkManager sharedInstance] post:@"ablum/update" params:params callback:^(id data, NSError *error) {
        !callback ?: callback(data, error);
    }];

}


/**
 *  向相册里添加图片
 *
 *  @param albumID  相册id
 *  @param pictures 以本地文件名作为客户端标识
 *  @param callback 回调
 */
+ (void)addPictureToAlbum:(NSInteger)albumID
                 pictures:(NSArray *)pictures
                 callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:@(albumID) forKey:@"ablumid"];
    [params setSafeObject:pictures forKey:@"pictures"];

    [[PPNetworkManager sharedInstance] post:@"ablum/picture/Add" params:params callback:^(id data, NSError *error) {
        !callback ?: callback(data, error);
    }];
}


/**
 *  从相册里删除图片
 *
 *  @param albumID   相册id
 *  @param pictures 图片id 数组
 *  @param callback  回调
 */
+ (void)deletePictureFromAlbum:(NSInteger)albumID
                      pictures:(NSArray *)pictures
                      callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:@(albumID) forKey:@"ablumid"];
    [params setSafeObject:pictures forKey:@"pictures"];

    [[PPNetworkManager sharedInstance] post:@"ablum/picture/remove" params:params callback:^(id data, NSError *error) {
        !callback ?: callback(data, error);
    }];
}

/**
 *  编辑图片信息
 *
 *  @param albumID     相册id
 *  @param pictureID   图片id
 *  @param pictureDesc 更新的描述描述描述
 *  @param callback    回调
 */
+ (void)updatePictureDescInAlbumID:(NSInteger)albumID
                         pictureID:(NSInteger)pictureID
                       pictureDesc:(NSString *)pictureDesc
                          callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:@(albumID) forKey:@"ablumid"];
    [params setSafeObject:@(pictureID) forKey:@"pictureid"];
    [params setSafeObject:pictureDesc forKey:@"description"];

    [[PPNetworkManager sharedInstance] post:@"ablum/picture/update" params:params callback:^(id data, NSError *error) {
        !callback ?: callback(data, error);
    }];
}

/**
 *  创建用户标签
 *
 *  @param names    ["我的标签1","我的标签2","我的标签3"]
 *  @param callback 回调
 */
+ (void)createTagWithNames:(NSArray *)names
                  callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:names forKey:@"names"];

    [[PPNetworkManager sharedInstance] post:@"tag/create" params:params callback:^(id data, NSError *error) {
        !callback ?: callback(data, error);
    }];
}

/**
 *  登录
 *
 *  @param loginType 0代表手机号登陆，1代表用pickpic号
 *  @param number    要登录的手机或者pickpick号
 *  @param password  //用privatekey进行MD5运算
 *  @param callback  回调
 */
+ (void)loginWithLoginType:(NSInteger)loginType
                    number:(NSString *)number
                  password:(NSString *)password
                  callback:(CompleteCallback)callback
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setSafeObject:@(loginType) forKey:@"loginType"];
    [params setSafeObject:number forKey:@"login"];
    [params setSafeObject:password forKey:@"password"];

    [[PPNetworkManager sharedInstance] post:@"user/login"
                                     params:params
                                   callback:^(id data, NSError *error) {
                                       !callback ?: callback(data, error);
                                   }];
}

@end
